home *** CD-ROM | disk | FTP | other *** search
- #include "AppMacros.h"
- #include "ToolTrapsPr.h"
-
- #include "CoreDialogUtilPr.h"
-
- /* DLOGStandardProc - uses button 1 as default, button 2 as cancel
- processes Return, Enter and cmd .
- */
- pascal Boolean DLOGStandardProc( DialogRef theDialog, EventRecord *theEvent, short *theItem )
- {
- short type;
- Rect box;
- char c;
- long endTicks;
- Boolean result;
- Handle item;
-
- c = (theEvent->message & charCodeMask);
-
- if (c == 13 || c == 3) /* return or enter */
- {
- GetDItem (theDialog, 1, &type, &item, &box);
-
- HiliteControl ((ControlHandle)item, true);
- Delay (8, &endTicks);
- HiliteControl ((ControlHandle)item, false);
-
- *theItem = 1;
- theEvent->what = mouseDown;
- result = true;
- }
- else if ((c == '.' && theEvent->modifiers & cmdKey) || (c == 0x1B)) /* cmd . */
- {
- GetDItem (theDialog, 2, &type, &item, &box);
-
- HiliteControl ((ControlHandle)item, true);
- Delay (8, &endTicks);
- HiliteControl ((ControlHandle)item, false);
-
- *theItem = 2;
- theEvent->what = mouseDown;
-
- result = true;
- }
- else
- result = false;
-
- return (result);
- }
-
- // GetItemHandle - returns the given item's control handle
- ControlHandle GetItemHandle( DialogRef theDlog, short theItem )
- {
- short itemType = 0;
- Rect itemRect = { 0, 0, 0, 0 };
- Handle cntHdl = nil;
-
- GetDialogItem( theDlog, theItem, &itemType, &cntHdl, &itemRect);
- return( (ControlHandle)cntHdl );
- }
-
- // SetItemHandle - sets the control handle according to some pre-defined constants (in "DialogUtilPr.h")
- void SetItemHandle( DialogRef theDlog, short theItem, short theCnt )
- {
- short itemType = 0;
- Rect itemRect = { 0, 0, 0, 0 };
- Handle cntHdl = nil;
-
- GetDialogItem( theDlog, theItem, &itemType, &cntHdl, &itemRect);
- switch( theCnt )
- {
- case pBWButtonOutlineProc:
- SetDItem( theDlog, theItem, itemType, (Handle)NewUserItemProc(indentBWButtonProc), &itemRect );
- break;
- }
- }
-
- // ItemVisible - returns whether the given item is visible or not
- Boolean ItemVisible( DialogRef theDlog, short theItem )
- {
- return( (**GetItemHandle( theDlog, theItem )).contrlVis == 255 );
- }
-
- // GetItemValue - returns the given item's control value
- short GetItemValue( DialogRef theDlog, short theItem )
- {
- return( GetControlValue( GetItemHandle( theDlog, theItem ) ) );
- }
-
- // SetItemValue - sets the given item's control value
- void SetItemValue( DialogRef theDlog, short theItem, short theValue )
- {
- SetControlValue( GetItemHandle( theDlog, theItem ), theValue );
- }
-
- // InvertItem - if a button is on, it is made off, and vica verca
- void InvertItem( DialogRef theDlog, short theItem )
- {
- ControlHandle cntHdl = nil;
-
- cntHdl = GetItemHandle( theDlog, theItem );
-
- if( cntHdl )
- SetControlValue( cntHdl, !( GetControlValue( cntHdl ) ) );
- }
-
- // SetTextValue - sets the text box to the number given
- void SetTextValue( DialogRef theDlog, short theItem, long theValue )
- {
- Str255 theString;
-
- NumToString( theValue, theString );
- SetIText( (Handle)GetItemHandle( theDlog, theItem ), theString );
- }
-
- // GetTextValue - returns the number in the given text box
- long GetTextValue( DialogRef theDlog, short theItem )
- {
- Str255 theString;
- long theValue = 0;
-
- GetIText( (Handle)GetItemHandle( theDlog, theItem ), theString );
- StringToNum( theString, &theValue );
-
- return( theValue );
- }
-
- // EnableDisableItem - enables or disables the dialog item
- void EnableDisableItem( DialogRef theDlog, short theItem, Boolean enable )
- {
- ControlHandle cntHdl = nil;
- short value = 0;
-
- if( enable )
- value = 0;
- else
- value = 255;
-
- cntHdl = GetItemHandle( theDlog, theItem );
-
- if( (**cntHdl).contrlHilite != value )
- HiliteControl( cntHdl, value );
- }
-
- // GetItemRect - gets the rectangle of the given control
- void GetItemRect( DialogRef theDlog, short theItem, Rect *theRect )
- {
- short itemType = 0;
- Handle cntHdl = nil;
-
- GetDialogItem( theDlog, theItem, &itemType, &cntHdl, theRect );
- }
-
- // indentBWButtonProc - draw a B&W outline round the button
- pascal void indentBWButtonProc( DialogRef theDialog, short theItem )
- {
- short type;
- Rect box;
- Handle itemHdl = nil;
- GrafPtr savePort = nil;
-
- GetPort( &savePort );
- SetPort( theDialog );
-
- ForeColor( blackColor );
-
- GetDItem( theDialog, theItem, &type, &itemHdl, &box );
-
- PenSize( 3, 3 );
- MInsetRect( box, -4, -4 );
- FrameRoundRect( &box, 16, 16 );
- PenNormal();
-
- SetPort( savePort );
- }